﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.SharePoint.WebPartPages;

namespace Dotsa.FAQ.FAQWebPart
{
    [ToolboxItemAttribute(false)]
    public class FAQWebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/Dotsa.FAQ/FAQWebPart/FAQWebPartUserControl.ascx";
        string listName = string.Empty;
        string listGuid = string.Empty;

        protected override void CreateChildControls()
        {
            FAQWebPartUserControl control = Page.LoadControl(_ascxPath) as FAQWebPartUserControl;
            control.ListName = listName;
            control.ListGuid = listGuid;
            Controls.Add(control);
        }

        //private string m_FAQListName;
        [Browsable(false), Category("Configuration"),
         Description("FAQ List Name"),
         DisplayName("FAQ List Name"), 
         WebPartStorage(Storage.Shared)]
        public string FAQListName
        {
            get
            {
                return listName;
            }
            set
            {
                listName = value;
            }
        }

        //private string m_FAQListName;
        [Browsable(false), Category("Configuration"),
         Description("FAQ List Guid"),
         DisplayName("FAQ List Guid"),
         WebPartStorage(Storage.Shared)]
        public string ListGuid
        {
            get
            {
                return listGuid;
            }
            set
            {
                listGuid = value;
            }
        }

        public override ToolPart[] GetToolParts()
        {
            List<ToolPart> parts = new List<ToolPart>();
            GenericListSelectorToolPart picker = new GenericListSelectorToolPart(this, "FAQListName");

            picker.Title = "Pick an FAQ List";
            parts.Add(picker);

            WebPartToolPart wptp = new WebPartToolPart();
            parts.Add(wptp);

            return parts.ToArray();
        }
    }
}
